#pragma once

#include "Workspace/IDocument.h"

interface IView;	class Workspace;	enum documentCategory; enum pageTypesetCategory; enum pageBindingCategory;

class Document : public IDocument
{
	typedef std::vector<IView*> ViewList;

public:
	BEGIN_DEFINE_CLASS(CLSID_Document)
		DEFINE_INTERFACE_ENTRY(IDocument)
	END_DEFINE_CLASS()

	Document();
	virtual ~Document();

	event_implement(DocumentOpenEventHandler,Opening);
	event_implement(DocumentEventHandler,Opened);
	event_implement(DocumentCloseEventHandler,Closed);
	event_implement(DocumentCloseEventHandler,Closing);
	event_implement(DocumentCloseEventHandler,Saving);
	event_implement(DocumentCloseEventHandler,Saved);

public:
	virtual const String& GetName() const;
	virtual vresult Save(const String& name);
	virtual IWorkspace* GetWorkspace() const;
	virtual bool  IsNew() const;
	virtual IConnection* GetConnection() const;
	virtual IObject* GetRoot() const;
	virtual void UpdateAllViews(IView* activeView);

	void RemoveView(IView* view);
	void AddView(IView* view);
	vresult New(const String& name,
						  Workspace* workspace,
						  documentCategory category,
						  pageTypesetCategory pageTypeset,
						  pageBindingCategory pageBinding,
						  uint32 pageCount,
						  real pageHeight,
						  real pageWidth,
						  real pageLeftMargin,
						  real pageTopMargin,
						  real pageRightMargin,
						  real pageBottonMargin);
	vresult Open(const String& name,Workspace* workspace);
	vresult Close();

protected:
	void SetName(const String& name);
	void SetRoot(IObject* root);

private:
	IObject* m_root;
	Workspace* m_workspace;
	sys::ObjectPtr m_connection;
	String m_name;
	ViewList m_linkedviews;
};
AUTO_REGISTER_CLASSMAP_ENTRY(Document)